package cc.linker.steplink.crm.commons;

import cc.linker.steplink.crm.commons.model.OssProperties;
import cc.linker.steplink.crm.commons.model.SystemProperties;
import cc.linker.steplink.crm.commons.model.WcPayProperties;
import cc.linker.steplink.crm.commons.oss.BucketOperations;
import cc.linker.steplink.crm.commons.oss.ObjectOperations;
import cc.linker.steplink.crm.commons.oss.OssService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;
import org.springframework.data.redis.core.RedisTemplate;

@Configuration
@PropertySource(value = "classpath:oss.properties", ignoreResourceNotFound = false)
public class CommonsConfiguration {

    @Autowired
    private RedisTemplate<String, String> redisTemplate;

    @Bean("systemProperties")
    public SystemProperties systemProperties() {
        return new SystemProperties();
    }

    @Bean("wcPayProperties")
    public WcPayProperties wcPayProperties() {
        return new WcPayProperties();
    }

    @Bean("ossProperties")
    public OssProperties ossProperties() {
        return new OssProperties();
    }

    @Bean
    public ObjectOperations objectOperations() {
        return new ObjectOperations(ossProperties());
    }

    @Bean
    public BucketOperations bucketOperations() {
        return new BucketOperations(ossProperties());
    }

    @Bean
    public OssService ossService() {
        return new OssService(objectOperations(), redisTemplate);
    }
}
